package com.csdemos.algs;

public class ListQueue extends List {

	Node tail;
	
	public ListQueue() {
		super();
		tail = null;
	}
	
	public void enqueue(String x) {
		if (tail == null) {
			head = tail = new Node(x, null);
		} else {
			Node last = new Node(tail.getData(), null);
			tail.setNext(last);
			tail = last;
		}
	}
	
	public String dequeue() {
		if (head == null) {
			throw new IllegalStateException("Queue is empty!");
		}
		String x = head.getData();
		head = head.getNext();
		if (head == null) {
			tail = null;
		}
		return x;
	}
}
